package cn.kgc.bdqn_studentinfomanager.controller;

import cn.kgc.bdqn_studentinfomanager.pojo.Model.BdqnStudentinfo;
import cn.kgc.bdqn_studentinfomanager.pojo.common.ServerResponse;
import cn.kgc.bdqn_studentinfomanager.pojo.dto.AddStudentDto;
import cn.kgc.bdqn_studentinfomanager.service.StudentService.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * by Shanshui CC on 2020/12/7 17:31
 */
@RestController
@RequestMapping("/student")
@CrossOrigin
public class StudentController {

    @Resource
    private StudentService studentService;


    /**
     * 招生老师界面\咨询师  进入时  加载学生信息
     */
    @RequestMapping(value = "/loadingStudentInfoByRecruitId")
    public ServerResponse loadingStudentInfoByRecruitId(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control", "no-cache");
//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");

        return studentService.LoadingStudentInfoByRecruitId(request.getHeader("token"));
    }

    /**
     * 专员  进入时  加载学生信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/loadingStudentInfoByComm")
    public ServerResponse loadingStudentInfoByComm(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control", "no-cache");
//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");

        return studentService.LoadingStudentInfoByByComm(request.getHeader("token"));
    }

    /**
     * 跳转至添加学生界面时，初始化省
     *
     * @return
     */
    @RequestMapping("loadingProvince")
    public ServerResponse loadingProvince(HttpServletRequest request) {
        return studentService.loadingProvince(request.getHeader("token"));
    }

    /**
     * 跳转至添加学生界面时，初始化市
     * @return
     */
    @RequestMapping("loadingCityByProvinceId")
    public ServerResponse loadingCityByProvinceId(HttpServletRequest request, String provinceId) {
        return studentService.loadingCityByProvinceId(request.getHeader("token"),provinceId);
    }

    /**
     * 新增学生信息
     *
     * @param addStudentDto
     * @param request
     * @return
     */
    @RequestMapping("/add")
    public ServerResponse add(AddStudentDto addStudentDto, HttpServletRequest request) {

        return studentService.add(addStudentDto, request.getHeader("token"));
    }

    /**
     * 统计学生数量 / 月
     *
     * @return
     */
    @RequestMapping("/totalestudentsnum")
    public ServerResponse totalestudentsnum(HttpServletRequest request) {
        return studentService.totalestudentsnum(request.getHeader("token"));
    }

    /**
     * 统计报名数量 / 月
     *
     * @return
     */
    @RequestMapping("/enrolledstudentsnum")
    public ServerResponse enrolledstudentsnum(HttpServletRequest request) {
        return studentService.enrolledstudentsnum(request.getHeader("token"));
    }


    /**
     * 统计学生列表 / 月
     *
     * @return
     */
    @RequestMapping("/totalestudents")
    public ServerResponse totalestudents(HttpServletRequest request) {
        return studentService.totalestudents(request.getHeader("token"));
    }


    /**
     * 统计学生报名列表 / 月
     *
     * @return
     */
    @RequestMapping("/enrolledstudents")
    public ServerResponse enrolledstudents(HttpServletRequest request) {
        return studentService.enrolledstudents(request.getHeader("token"));
    }


    /**
     * 修改学生信息
     *
     * @param bdqnStudentinfo
     * @return
     */

//    @RequestMapping("/updateinfo")
//    public ServerResponse updateinfo(BdqnStudentinfo bdqnStudentinfo) {
//        return studentService.updateinfo(bdqnStudentinfo);
//    }

    /**
     * 点击页面时将所有学生信息加载出来
     *
     * @return
     */
    @RequestMapping("/loadingStudentInfo")
    public ServerResponse loadingStudentInfo(HttpServletRequest request) {
        return studentService.loadingStudentInfo(request.getHeader("token"));
    }

    /**
     * 模糊查询学生信息
     *
     * @param condition
     * @param status
     * @param request
     * @return
     */
    @RequestMapping("/getstudent")
    public ServerResponse getstudent(String condition, String status, HttpServletRequest request) {

        return studentService.getstudentinfo(condition, status, request.getHeader("token"));
    }


    /**
     * 展示一条学生信息
     *
     * @param studentId
     * @return
     */
    @RequestMapping("/showStudentInfoById")
    public ServerResponse showStudentInfoById(HttpServletRequest request,String studentId) {
        return studentService.showStudentInfoById(request.getHeader("token"),studentId);
    }

    /**
     * 修改学生信息前预准备   (根据学生Id加载所有省份集合和当前学生所在的省份)
     * @return
     */
    @RequestMapping("getProvinceListAndProvince")
    public ServerResponse getProvinceListAndProvince(HttpServletRequest request,String studentId){
        return studentService.getProvinceListAndProvince(request.getHeader("token"),studentId);
    }
    /**
     * 修改学生信息前预准备   (根据学生Id加载所有城市集合和当前学生所在的城市)
     * @return
     */
    @RequestMapping("getCityListAndCity")
    public ServerResponse getCityListAndCity(HttpServletRequest request,String studentId){
        return studentService.getCityListAndCity(request.getHeader("token"),studentId);
    }


    /**
     * 修改学生信息前预准备   (展示所有意向描述)
     * @param request
     * @param studentId
     * @return
     */
//    @RequestMapping("showAllDescription")
//    public ServerResponse showAllDescription(HttpServletRequest request,String studentId){
//        return studentService.showAllDescription(request.getHeader("token"),studentId);
//    }


    /**
     * 展示一条学生信息后点击保存    (修改学生信息)
     *
     * @param addStudentDto
     * @return
     */
    @RequestMapping("/saveStudentInfoById")
    public ServerResponse saveStudentInfoById(AddStudentDto addStudentDto,HttpServletRequest request) {
        return studentService.saveStudentInfoById(addStudentDto,request.getHeader("token"));
    }

}